﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Controls;
using System.Windows.Media;
using System.Windows.Input;

using ParamSetCollection.General.Parameters.Normal;

namespace NeoReflow.UI.Example.Controls
{
    class PVTextBox : TextBox, IParamCtrl
    {
        public ParameterUnit pu = null;
        public string m_paramTag = "";

        public ParameterUnit Pu 
        { 
            get { return pu; } 
            set { 
               if(pu!=null)
                    pu.OnValueRenew -= Pu_OnValueRenew;
                pu = value;
                Text = pu.ViewValue;
                pu.OnValueRenew += Pu_OnValueRenew;
            } 
        }



        public string ParamTag { get { return m_paramTag; } set { m_paramTag = value; } }

        public PVTextBox()
            : base()
        {
            IsReadOnly = true;

        }

        public void ConfirmParamSet()
        {
            pu.SetValue(Text);
        }



        public void Dispose()
        {
            pu = null;
        }

        private void Pu_OnValueRenew(string viewValue)
        {
            Text = viewValue;
        }
    }
}
